

#ifndef MESH_H
#define MESH_H

#include "D3D11.h"
#include "xnamath.h"
#include "Types.h"
#include "DeviceManager.h"
#include "Effect.h"
#include "ModelObj.h"

struct MeshPart
{
	int mStartIndex;
	int mIndexCount;

	ID3D11ShaderResourceView* mpDiffuseMap;
	ID3D11ShaderResourceView* mpNormalMap;
	XMVECTOR mDiffuse;
	XMVECTOR mSpecular;
	float mShininess;

	MeshPart()
	{
		mpDiffuseMap = NULL;
		mpNormalMap = NULL;
	}
};

class Mesh
{
public:
	static Mesh* Create(const MeshData *pMeshData, const DeviceManager* pDeviceManager);
	
	ID3D11InputLayout* mpInputLayout;

	void Release();
	void Draw() const;
	void Draw(int index) const;
	void DrawPatch() const;
	void DrawPatch(int index) const;
	int GetVertexCount() const;
	int GetIndexCount() const;
	int GetMeshCount() const;

	MeshPart* GetMeshPart(int index) const;

private:
	Mesh();
	const DeviceManager* mpDeviceManager;
	ID3D11Buffer* mpVertexBuffer;
	ID3D11Buffer* mpIndexBuffer;
	MeshPart* mpMeshParts;

	int mVertexCount;
	int mIndexCount;
	int mMeshCount;

	inline void PrepareDraw() const;

};

#endif